package com.jkhan.demo.inheritance;

/**
 * @ClassName AbstractTest2
 * @Description TODO
 * @Author F117
 * @Date 2021/12/29 22:30
 **/
public class AbstractTest2 {
    public static void main(String[] args) {
        method(new Student());//匿名对象

        Worker worker = new Worker();
        method(worker);//非匿名类非匿名对象

        method(new Worker());//非匿名类匿名对象

        System.out.println("********************");

        //创建一个匿名子类
        Person p = new Person() {
            @Override
            public void eat() {
                System.out.println("person eat");
            }

            @Override
            public void breath() {
                System.out.println("person breath");
            }
        };
        method(p);

        System.out.println("**********************");

        //创建匿名子类的匿名对象
        method(new Person() {
            @Override
            public void eat() {
                System.out.println("person eat food");
            }

            @Override
            public void breath() {
                System.out.println("person breath fresh air");
            }
        });
    }

    public static void method(Student s) {

    }

    public static void method(Person p) {
        p.eat();
        p.breath();
    }
}

class Worker extends Person {

    @Override
    public void breath() {

    }

    @Override
    public void eat() {

    }
}
